package org.openkoala.koala.popup;

import org.eclipse.core.resources.IResource;
import org.openkoala.koala.exception.KoalaException;
import org.openkoala.koala.util.ProjectQueryUtil;
import org.openkoala.koala.widget.Module;
import org.openkoala.koala.widget.Project;

public abstract class SecurityModuleBaseAction extends BaseAction {

	private Project project;
	private Module module;

	private IResource selectedResource;
	
	public Project getProject() {
		return project;
	}

	public Module getModule() {
		return module;
	}

	public IResource getSelectedResource() {
		return selectedResource;
	}

	boolean initAndVerify() {
		try {
			initProjectAndModule();
		} catch (KoalaException e) {
			popupErrorMessage(e.getMessage());
			e.printStackTrace();
			return false;
		}
		
		if (!getModule().getModuleType().equals("war")) {
			popupErrorMessage("该模块不是视图层模块");
			return false;
		}
		
		return true;
	}
	
	private void initProjectAndModule() throws KoalaException {
		selectedResource = getResource();
		String selectedPath = selectedResource.getLocationURI().getPath();
		project = ProjectQueryUtil.getProject(selectedPath);
		module = ProjectQueryUtil.getModule(selectedPath, project);
	}
	
}
